package com.gujiangbo.application.controller;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.gujiangbo.application.service.UserFeignClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @GetMapping("hello")
    @SentinelResource(value = "Sentinel_SpringCloud", blockHandler = "exceptionHandler")
    public String hello() {
        return "Hello World !!";
    }

    public String exceptionHandler(BlockException ex) {
        ex.printStackTrace();
        return "触发熔断机制！服务器异常，请稍后再试！";
    }

    @Autowired
    private UserFeignClient userFeignClient;

    @GetMapping("/testFeign")
    public String testFeign() {
        return userFeignClient.getUser(1L);
    }

}
